version: "0.1"

services:
  # First part.
  # Creates a genesis state for the beacon chain using a YAML configuration file and
  # a deterministic set of 64 validators.
  create-beacon-chain-genesis:
    container_name: beacon_chain_initializer
    image: "gcr.io/prysmaticlabs/prysm/cmd/prysmctl:HEAD-ec954e"
    command:
      - testnet
      - generate-genesis
      - --fork=capella
      - --num-validators=64
      # - --genesis-time-delay=15
      - --output-ssz=/consensus/genesis.ssz
      - --chain-config-file=/consensus/config.yaml
      - --geth-genesis-json-in=/execution/example_genesis.json
      - --geth-genesis-json-out=/execution/genesis.json
    volumes:
      - ./consensus:/consensus
      - ./execution:/execution
  
  # Second part.
  # Generate jwt for beacon chain.
  create-jwt:
    container_name: jwt_creator
    image: "docker.io/frapsoft/openssl:latest"
    command: rand -hex 32 | tr -d "\n" > "./jwtsecret/jwt.hex"
    depends_on:
      create-beacon-chain-genesis:
        condition: service_completed_successfully
    volumes: 
      - ./jwtsecret:/jwtsecret
  
  # Sets up the genesis configuration for the go-ethereum client from a JSON file.
  geth-genesis:
    container_name: geth_initializer
    image: "ethereum/client-go:stable"
    command: --datadir=/execution init /execution/genesis.json
    depends_on:
      create-jwt:
        condition: service_completed_successfully
    volumes:
      - ./execution:/execution
      - ./execution/genesis.json:/execution/genesis.json
  
  geth-account:
    container_name: account
    image: "ethereum/client-go:stable"
    command: account import --datadir=/execution --password=/execution/password.txt /execution/secret.json
    depends_on:
      geth-genesis:
        condition: service_completed_successfully
    volumes:
      - ./execution:/execution

  # Runs the go-ethereum execution client with the specified, unlocked account and necessary
  # APIs to allow for proof-of-stake consensus via Prysm.
  geth:
    container_name: geth
    image: "ethereum/client-go:stable"
    command:
      - --http
      - --http.api=debug,net,eth,web3,txpool,admin
      - --port=30312
      - --http.addr=0.0.0.0
      - --http.corsdomain=*
      - --ws
      - --ws.api=debug,net,eth,web3,txpool,admin
      - --ws.addr=0.0.0.0
      - --ws.origins=*
      - --authrpc.vhosts=*
      - --authrpc.addr=0.0.0.0
      - --authrpc.jwtsecret=/jwtsecret/jwt.hex
      - --datadir=/execution
      - --allow-insecure-unlock
      - --unlock=0x123463a4b065722e99115d6c222f267d9cabb524
      - --password=/execution/password.txt
      - --nodiscover
      - --syncmode=full
      - --networkid=32382
    ports:
      - 30303:30303
      - 8551:8551
      - 8545:8545
      - 8546:8546
    depends_on:
      geth-genesis:
        condition: service_completed_successfully
      geth-account:
        condition: service_completed_successfully
    volumes:
      - ./execution:/execution
      - ./jwtsecret:/jwtsecret

  # Runs a Prysm beacon chain from a specified genesis state created in the previous step
  # and connects to go-ethereum in the same network as the execution client.
  # The account used in go-ethereum is set as the suggested fee recipient for transactions
  # proposed via the validators attached to the beacon node.
  beacon-chain:
    container_name: beacon_chain
    image: "gcr.io/prysmaticlabs/prysm/beacon-chain:v4.0.8"
    command:
      - --datadir=/consensus/beacondata
      # No peers to sync with in this testnet, so setting to 0
      - --min-sync-peers=0 
      - --genesis-state=/consensus/genesis.ssz
      - --bootstrap-node=
      - --interop-eth1data-votes
      - --chain-config-file=/consensus/config.yaml
      # We specify the chain id used by our execution client
      - --contract-deployment-block=0
      - --chain-id=32382
      - --rpc-host=0.0.0.0
      - --rpc-port=4001
      - --p2p-tcp-port=13000
      - --grpc-gateway-host=0.0.0.0
      - --grpc-gateway-port=4100
      - --execution-endpoint=http://geth:8551
      - --accept-terms-of-use
      - --jwt-secret=/jwtsecret/jwt.hex
      - --suggested-fee-recipient=0x123463a4b065722e99115d6c222f267d9cabb524
      - --minimum-peers-per-subnet=0
      - --enable-debug-rpc-endpoints
    depends_on:
      create-beacon-chain-genesis:
        condition: service_completed_successfully
      create-jwt:
        condition: service_completed_successfully
      geth:
        condition: service_started
    ports:
      - 12000:12000
      - 13000:13000
      - 4000:4000
      - 4001:4001
      - 4100:4100
      - 3500:3500
      - 8080:8080
      - 8081:8080
      - 6060:6060
      - 9090:9090
    volumes:
      - ./consensus:/consensus
      - ./execution:/execution
      - ./jwtsecret:/jwtsecret

  # We run a validator client with 64, deterministically-generated keys that match
  # The validator keys present in the beacon chain genesis state generated a few steps above.
  validator:
    container_name: validator
    image: "gcr.io/prysmaticlabs/prysm/validator:v4.0.8"
    command:
      - --beacon-rpc-provider=beacon-chain:4001
      - --datadir=/consensus/validatordata
      - --accept-terms-of-use
      - --interop-num-validators=64
      - --interop-start-index=0
      - --chain-config-file=/consensus/config.yaml
    depends_on:
      beacon-chain:
        condition: service_started
    volumes:
      - ./consensus:/consensus